package io;

import org.junit.Test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @Author: zhenzhong.wang
 * @Time: 2018/4/20 15:21
 */
public class SocketChannelDemo {

  @Test
  public void testOne() throws IOException {
    SocketChannel socketCha = SocketChannel.open();
    socketCha.connect(new InetSocketAddress("47.98.34.171", 80));
    ByteBuffer buf = ByteBuffer.allocate(1024);

    while (socketCha.read(buf) != -1) {
      buf.flip();
      while (buf.hasRemaining()) {
        System.out.print(buf.get());
      }
      buf.clear();
    }
  }

}
